<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--#include file="DataLoad.asp"-->
<!--#include file="inc/ImportMethod.asp"-->
<%Call CheckAdmin2()%>

<html>
<head>
<title><%=GuildName%> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<%=StylePath%>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<%=StylePath%>/styleplus.js"></script>

</head>

<body>
<div class="header">
<!--#include file="menu.asp"-->
</div>
<div class="main">

<%
Select Case Request("Action")
Case "Import"
	Call sqlInitializeData(Request.Form("FormatData"),Request.Form("class_name"))
	Response.write "<div class='message'>导入成功,你可以: <a href='admin_MerDKPImport.asp' class='abtn3'>继续导入</a> <a href='admin_SpecEvent.asp' class='abtn'>查看导入的调分事件</a></div>"
Case else
%>

<form method=post action="?Action=Import">
<table class="outframe">
<tr><th>从外部数据导入初始化分值</th></tr>
<tr><td>复制MerDKP数据或者整理好的Excel表格[<a href="http://sites.google.com/site/wowfsdkp/Home/shi-yong-jiao-cheng" target="_blank">?</a>]到这里,每次只导入其中一个DKP分类</td></tr>
<tr><td>第1步:<br><textarea name="DKPDATA" style="width:500px;height:200px;">
MerDKP示例:

MerDKP_Table[1] = { &lt;&lt; -----以这行开始
{name="成员甲",class="猎人",dkp=0.00,online=1},
{name="成员乙",class="德鲁伊",dkp=5.00,online=1},
};
MerDKP_Table[1].title="T5级";
MerDKP_Table[1].whisper="1";
MerDKP_Table[1].key="T5级"; &lt;&lt; ----- 以这行结束
</textarea></td></tr>
<tr><td>第2步:<br><a href="javascript:void(0)" name="btn1" class="abtn">来自MerDKP</a> <a href="javascript:void(0)" name="btn2" class="abtn">来自Excel</a> 选择你的数据来源</td></tr>

<tr><td><textarea name="FormatData" style="width:500px;height:200px;"></textarea></td></tr>
<tr><td>转换后的数据应该是像这样: 名字,职业,DKP,名字,职业,DKP, ... 如果不是请勿提交</td></tr>
<tr><td>第3步:<br>选择目标分类 <%=formselect("raid_class","id","class_name"," ")%></td></tr>
<tr><td>注意:请勿重复提交同一成员的同一分值多次,这样会造成双倍分值, 完成后可以在调分记录中再次检查</td></tr>
<tr><td><input type="submit" value="导入"> </td></tr>
<tr><td>另外:只有当某成员在FSDKP的活动中有记录时才会在DKP表中被列出</td></tr>
</table>

</form>

<%
End Select
%>
</div>
<div id="footer"><!--#include file="footer.asp"--></div>


<script language="JavaScript">
$("a[name=btn1]").click( function () {
	$("textarea[name=FormatData]").val(cMerDKP($("textarea[name=DKPDATA]").val()));
});

$("a[name=btn2]").click( function () {
	$("textarea[name=FormatData]").val(cExcel($("textarea[name=DKPDATA]").val()));
});

function cMerDKP(txt) {
	var ArrDKP = new Array();
	//清理空格换行
	var Rxtxt = txt.replace( /[\n\r\s]/g , "");
	//取得DKP分类部分
	Rxtxt = Rxtxt.match(/(MerDKP_Table\[\d\])=\{.*\1.key=\".*\";/g);
	//获得组名字
	var strGroupName = Rxtxt[0].match(/\.title=\"(.[^\"]*)\"/);
	//获得按条分数组
	Rxtxt = Rxtxt[0].match(/\{name=\"(.[^\"]*)\",class=\"(.[^\"]*)\",dkp=(.[^,]*),online=\d\},/g);
	//获得2维数组{条目数,2} 0职业 1名字 2分数
	for (i =0 ; i < Rxtxt.length ; i++ ) {
		Rxtxt[i] = Rxtxt[i].match(/\{name=\"(.[^\"]*)\",class=\"(.[^\"]*)\",dkp=(.[^,]*),online=\d\},/)
		ArrDKP[i] = [ Rxtxt[i][1] ,Rxtxt[i][2],Rxtxt[i][3]];
	}
	return ArrDKP
};

function cExcel(txt) {
	var ArrDKP = new Array();
	var Rxtxt = txt.replace( /[\n\r\s]/g , ",");
	var Rxtxt = Rxtxt.replace( /,,/g , "");
	var Rxtxt = Rxtxt.replace( /,,/g , "");
	var Rxtxt = Rxtxt.replace( /^,/g , "");
	var Rxtxt = Rxtxt.replace( /,$/g , "");
	return Rxtxt
};

</script>

</body>
</html>
<%
Sub sqlInitializeData(data,c)
	Dim arrData
	arrData = Split(data,",")
	For ia = 0 To UBound(arrData) Step 3
		SQL="Select * from player where Player_name='"&arrData(ia)&"'"
		rs.open sql,conn,1,1
		if rs.eof or rs.bof then
			rs.close
			sql="select * from player where (id is null)"
			rs.open sql,conn,1,3
			rs.addnew
			rs("player_name")=arrData(ia)
			rs("player_profession")=getFormatProfessionName(arrData(ia+1))
			rs("player_tribe")="未知"
			rs("player_level")=DefalutPlayerLevel
			rs("player_honor")=""
			rs("player_jointime")=date()
			rs("player_guildlevel")=""
			rs("player_DKP")=0
			rs("player_skill_1")=""
			rs("player_skill_2")=""
			rs("player_note")=""
			rs("player_activist")=0
			rs("player_looted")=""
			rs("player_raidnum")=0
			rs("player_state")="正常"
			rs.update
			Response.write "添加成员: "&arrData(ia)&" Done"
			rs.close
		else
			Response.write "现有成员: "&arrData(ia)
			rs.close
		end If

		Call sqlSpecEvent(arrData(ia), c, arrData(ia+2), "其它", "系统初始化分值导入")
	Next
End Sub


Sub sqlSpecEvent(n, rc, dkp, ec, eo) 'str名字, DKP分类ID, dkp, str调分类型, 解释
	sql="select * from raid_event where (id is null)"
	rs.open sql,conn,1,3
	rs.addnew
		rs("event_object")=n
		rs("raid_class")=CInt(rc)
		rs("event_dkp")=dkp
		rs("event_class")=ec
		rs("event_object2")=eo
		rs("event_time")=Date()
	rs.update
	Response.write " 调分: "&dkp&" Done<br>"
	rs.close
End Sub
%>